//
// Created by 17775 on 2024/10/17.
//


#include <memory>
#include "Single_CrossSection.h"

Single_CrossSection::Single_CrossSection() {

}

std::shared_ptr<PowerProfileData<std::vector<float>>> Single_CrossSection::getCrossSectionData() {
    bool _bCrossSectionValid = false;
    std::shared_ptr<PowerProfileData<std::vector<float>>> crossData;
    RayCi_Single_CrossSection_isValid(_iSingleDocId, 0, &_bCrossSectionValid);
    if(_bCrossSectionValid) {
        int iDataLength = 0;
        RayCi_Single_CrossSection_getDataLength(_iSingleDocId, 0, &iDataLength);
        if(iDataLength != 0) {
            std::vector<float> dXPositions_buffer;
            std::vector<float> dYPositions_buffer;
            std::vector<float> dIntensity_buffer;
            std::vector<float> dFitFunction_buffer;
            dXPositions_buffer.resize(iDataLength);
            dYPositions_buffer.resize(iDataLength);
            dIntensity_buffer.resize(iDataLength);
            dFitFunction_buffer.resize(iDataLength);
            RayCi_Single_CrossSection_getDataAsBinary(_iSingleDocId, 0, &dXPositions_buffer[0], &iDataLength, &dYPositions_buffer[0],
                                                      &iDataLength, &dIntensity_buffer[0], &iDataLength, &dFitFunction_buffer[0], &iDataLength);
            crossData = std::make_shared<PowerProfileData<std::vector<float>>>(dXPositions_buffer, dIntensity_buffer);
        }
    }

    return crossData;
}

Single_CrossSection::~Single_CrossSection() {

}